package com.lahuan.demo.controller;


import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import com.lahuan.demo.service.TestDistributedService;
import com.lahuan.demo.entity.TestDistributed;
import javax.validation.Valid;

/**
 * <p>
 * test_distributed 控制器
 * </p>
 * @author lahuan
 * @since 2021-12-05
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value = "test_distributed", tags = "test_distributed接口")
@RequestMapping("/demo/testDistributed")
public class TestDistributedController {

    private final TestDistributedService testDistributedService;

    @ApiOperation(value = "获取test_distributed分页列表",notes="获取test_distributed分页列表")
    @GetMapping("")
    public  Result<Page<TestDistributed>> testDistributedList(Page< TestDistributed> page, TestDistributed query) {
        return Result.ok(testDistributedService.page(page, Wrappers.query(query)));
    }

    @ApiOperation(value = "根据id获取test_distributed",notes="根据id获取test_distributed")
    @ApiImplicitParam(name = "id", value = "test_distributedid", required = true, dataType = "Long ")
    @GetMapping("/{id}")
    public Result<TestDistributed> testDistributedGetById(@PathVariable Long id) {
        return Result.ok(testDistributedService.getById(id));
    }

    @ApiOperation(value = "添加test_distributed",notes="新增test_distributed")
    @PostMapping("")
    public Result<Boolean> testDistributedSave(@RequestBody @Valid  TestDistributed testDistributed) {
        return Result.ok(testDistributedService.save(testDistributed));
    }

    @ApiOperation(value = "修改test_distributed",notes="根据id修改test_distributed")
    @PutMapping("/{id}")
    public Result<Boolean> testDistributedUpdate(@RequestBody @Valid  TestDistributed testDistributed, @PathVariable Long id) {
        testDistributed.setId(id);
        return Result.ok(testDistributedService.updateById(testDistributed));
    }

    @ApiOperation(value = "删除test_distributed",notes="根据id删除test_distributed")
    @ApiImplicitParam(name = "id", value = "test_distributedid", required = true, dataType = "Long ")
    @DeleteMapping("/{id}")
    public Result<Boolean> testDistributedDelete(@PathVariable Long id) {
        return Result.ok(testDistributedService.removeById(id));
    }


}
